package com.seagull.core.test.desing.xiangyuan;

import java.util.HashMap;
import java.util.Map;

/**
 * @author:jian.zhou
 * @DATE: 2017/12/27.
 * @Version:0.0.1
 * @Desc:
 */
public class FlyweightFactory {

    private Map<Character, Flyweight> files = new HashMap<Character, Flyweight>();


    public Flyweight factory(Character state) {
        //先从已有的缓存列表中查询对象是否已存在
        Flyweight flyweight = files.get(state);
        if (flyweight == null) {
            //如果对象不存在，则重新创建一个新的Flyweight对象
            flyweight = new ConcreteFlyweight(state);
            //将新生成的对象放入缓存列表中 \
            files.put(state, flyweight);
        }
        //返回对象
        return flyweight;
    }



}
